/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.admin;

import JDBCUtil.MyConn;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;

/**
 *
 * @author Danh
 */
public class Accounts implements Serializable {

    private int accountId;
    private String username;
    private String password;
    private String email;
    private boolean status;
    private String role;
    Connection conn;

    public Accounts(int accountId, String username, String password, String email, boolean status, String role) {
        this.accountId = accountId;
        this.username = username;
        this.password = password;
        this.email = email;
        this.status = status;
        this.role = role;
    }

    public Accounts() {
        try {
            conn = MyConn.getConnection();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public int getAccountId() {
        return accountId;
    }

    public void setAccountId(int accountId) {
        this.accountId = accountId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public boolean update() {
        try {
            System.out.println(password + "");
            PreparedStatement pstmt = conn.prepareStatement("UPDATE Accounts SET User_Password=?,User_Name=?,User_Email=?, Account_Status=?,Account_Role=? WHERE Account_Id=?");
            pstmt.setNString(1, this.password);
            pstmt.setNString(2, this.username);
            pstmt.setNString(3, this.email);
            pstmt.setBoolean(4, this.status);
            pstmt.setNString(5, this.role);
            pstmt.setInt(6, this.accountId);
            int eu = pstmt.executeUpdate();
            if (eu > 0) {
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}